feat: TealTiger governance plugin for Dify - #425
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an initial TealTiger “governance_scan” tool package intended for use as a Dify tool plugin, exposing a visual node configuration and a Python implementation that invokes TealTiger for a governance decision.
Changes:
- Introduces Dify tool + provider metadata (manifest, provider credentials, tool definition YAML).
- Implements
governance_scantool logic in Python using the TealTiger SDK. - Adds Python dependency declaration for the plugin package.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/dify-plugin-tealtiger/tools/governance_scan.yaml | Defines the Dify tool’s identity and configuration parameters for governance scanning. |
| packages/dify-plugin-tealtiger/tools/governance_scan.py | Implements the tool invocation logic using TealTiger’s Python SDK. |
| packages/dify-plugin-tealtiger/requirements.txt | Declares the plugin’s Python dependency on tealtiger. |
| packages/dify-plugin-tealtiger/provider/tealtiger.yaml | Declares the provider credential schema (api_key) for Dify. |
| packages/dify-plugin-tealtiger/manifest.yaml | Registers the plugin/package metadata for Dify. |
Suppressed comments (3)
packages/dify-plugin-tealtiger/tools/governance_scan.py:35
res.securityis treated like a dict (.get(...)), but in TealTiger’s Python examples it’s accessed as an attribute (response.security.decision). As written, this will raise at runtime and fall into the exception handler, causing scans to DENY even when they should ALLOW. Also, returningsecurityobjects directly may not be JSON-serializable.
res = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": content}]
)
packages/dify-plugin-tealtiger/tools/governance_scan.py:29
- This "governance scan" tool currently calls
client.chat.completions.create(...), which invokes an LLM request. The linked Dify integration requirements in this repo describe a deterministic governance node with no LLM in the governance path (scan-only). Consider using TealTiger’s scan/evaluate APIs (e.g., TealGuard/TealEngine) so the tool can scan content without generating completions or incurring model cost/latency.
if budget > 0:
client_args["budget"] = budget
client = TealOpenAI(**client_args)
packages/dify-plugin-tealtiger/tools/governance_scan.py:12
- The tool currently (1) doesn’t fail fast with an actionable message when
api_keyis missing and (2) doesn’t wire secret scanning or budget limits into the TealTiger client, even though the tool’s description/requirements mention secrets and budget configuration. Consider validating credentials up front and passingsecret_detection+budgetintoTealOpenAI.
api_key = self.runtime.credentials.get("api_key")
content = tool_parameters.get("content", "")
pii_detection = tool_parameters.get("pii_detection", True)
prompt_injection = tool_parameters.get("prompt_injection", True)
content_moderation = tool_parameters.get("content_moderation", True)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from dify_plugin import Tool | ||
| from typing import Any, Dict | ||
| import os | ||
| from tealtiger import TealOpenAI |
| - name: content_moderation | ||
| type: boolean | ||
| required: false | ||
| default: true | ||
| label: | ||
| en_US: Enable Content Moderation |
| @@ -0,0 +1 @@ | |||
| tealtiger>=0.1.0 | |||
|
Thanks @lleonardo-franco — Dify integration is a great addition (n8n + Dify gives TealTiger coverage across the two biggest visual AI workflow builders). Quick check: did the latest commit address the tealtiger>=1.4.0 version pin and the missing secret_detection / budget YAML params that Copilot flagged? If so, LGTM — merging. |
|
Yes, just pushed a new commit addressing those points!
Thanks for the review, let me know if there's anything else! |
Closes #329. This PR introduces a Dify tool plugin for TealTiger Governance. It provides a visual node to scan text for policy violations and tracks cost via the TealTiger Python SDK.